package 算法.LeetCode91.每日打卡题目;

import 算法.NiuKe.ListNode;

/**
 * @author: 谢君臣
 * @create: 2021-02-07 16:26
 * @founction: XXXX
 */
public class day07 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        rotateRight(head,2);
    }
    public static ListNode rotateRight(ListNode head, int k) {
        if (head==null||head.next==null)
            return head;
        ListNode end = head;
        int length = 1;
        while (end.next!=null){
            end = end.next;
            length++;
        }
        k = length-(k%length);
        while (k>0){
            ListNode node = new ListNode(head.val,null);
            head = head.next;
            end.next = node;
            end = end.next;
            k--;
        }
        return head;
    }
}
